<?php

namespace App\Console\Commands;

use App\Model\DevicePowerLog;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class PowerLogCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'power:log';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '设备删除心跳';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $currentTime = time();
        $oneWeekAgo = $currentTime - (5 * 24 * 60 * 60); // 7天 * 24小时 * 60分钟 * 60秒
        $oneWeekAgoDate = date('Y-m-d H:i:s',$oneWeekAgo);
//        Log::info('一周前日期:'.$oneWeekAgoDate);
        DevicePowerLog::query()
            ->where('created_at','<=',$oneWeekAgoDate)->limit(10000)
            ->orderBy('id','asc')
            ->delete();
    }

}
